package com.ulic.customerManApplication.util.time;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.ulic.customerManApplication.constant.CONSTANT;

public class DateTime {
	public static String getDate(String pattern){
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);
		return sdf.format(new Date());
	}
	
	public static String getFormalDate(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		return sdf.format(date);
	}
	
	public static String getFormalDateTime(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(date);
	}
	
	/**
	 * 根据日期类型字符串得到某天是星期几
	 * @param date	2011-09-02
	 * @return 一，二，三，四，五，六，日
	 */
	public static String getDayInWeek(String date) throws Exception {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		@SuppressWarnings("deprecation")
		int dayInWeek = sdf.parse(date).getDay();
		String weekDay = "一";
		if(dayInWeek == 0) {
			weekDay = "日";
		}
		if(dayInWeek == 1) {
			weekDay = "一";
		}
		if(dayInWeek == 2) {
			weekDay = "二";
		}
		if(dayInWeek == 3) {
			weekDay = "三";
		}
		if(dayInWeek == 4) {
			weekDay = "四";
		}
		if(dayInWeek == 5) {
			weekDay = "五";
		}
		if(dayInWeek == 6) {
			weekDay = "六";
		}
		return weekDay;
	}
	
	public static void main(String args[]){
		System.out.println(DateTime.getDate(CONSTANT.TimePattern));
	}
}
